package com.approval.approvalapp.util.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/3/19.
 */

public abstract class BaseFragment extends Fragment {
    protected View mRoot;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (mRoot != null) {
            ViewGroup parent = (ViewGroup) mRoot.getParent();
            if (parent != null)
                parent.removeView(mRoot);
        } else {
            mRoot = inflater.inflate(getLayoutId(), container, false);
            ButterKnife.bind(this, mRoot);
            initView(mRoot);
            initData();
        }
        return mRoot;
    }

    protected abstract int getLayoutId();

    public abstract void initView(View view);

    public abstract void initData();

    @Override
    public void onDestroy() {
        super.onDestroy();
        mRoot = null;
        ButterKnife.unbind(this);
    }
}
